home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / EDSCRIPT.ICN < prev    next >
Text File  |  1992-12-30  |  2KB  |  82 lines

  1. ############################################################################
  2. #
  3. #    File:     edscript.icn
  4. #
  5. #    Subject:  Program to produce script for ed(1)
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program takes specifications for global edits from standard
  14. #  input and outputs an edit script for the UNIX editor ed to standard output.
  15. #  Edscript is primarily useful for making complicated literal sub-
  16. #  stitutions that involve characters that have syntactic meaning to
  17. #  ed and hence are difficult to enter in ed.
  18. #  
  19. #     Each specification begins with a delimiter, followed by a tar-
  20. #  get string, followed by the delimiter, followed by the replace-
  21. #  ment string, followed by the delimiter.  For example
  22. #  
  23. #          |...|**|
  24. #          |****||
  25. #  
  26. #  specifies the replacement of all occurrences of three consecutive
  27. #  periods by two asterisks, followed by the deletion of all
  28. #  occurrences of four consecutive asterisks.  Any character may be
  29. #  used for the delimiter, but the same character must be used in
  30. #  all three positions in any specification, and the delimiter char-
  31. #  acter cannot be used in the target or replacement strings.
  32. #  
  33. #  Diagnostic:
  34. #  
  35. #     Any line that does not have proper delimiter structure is noted
  36. #  and does not contribute to the edit script.
  37. #  
  38. #  Reference:
  39. #  
  40. #     "A Tutorial Introduction to the UNIX Text Editor", Brian W. Kernighan.
  41. #  AT&T Bell Laboratories.
  42. #  
  43. ############################################################################
  44.  
  45. procedure main()
  46.    local line, image, object, char
  47.    while line := read() do {
  48.       line ? {
  49.          char := move(1) | {error(line); next}
  50.          image := tab(find(char)) | {error(line); next}
  51.          move(1)
  52.          object := tab(find(char)) | {error(line); next}
  53.          }
  54.       write("g/",xform(image),"/s//",xform(object),"/g")
  55.    }
  56.    write("w\nq")
  57. end
  58.  
  59. #  process characters that have meaning to ed
  60. #
  61. procedure insert()
  62.    static special
  63.    initial special := '\\/^&*[.$'
  64.    suspend {
  65.       tab(upto(special)) ||
  66.       "\\" ||
  67.       move(1) ||
  68.       (insert() | tab(0))
  69.       }
  70. end
  71.  
  72. procedure error(line)
  73.    write(&errout,"*** erroneous input: ",line)
  74. end
  75.  
  76. #  transform line
  77. #
  78. procedure xform(line)
  79.    line ?:= insert()
  80.    return line
  81. end
  82.